package com.czp.person.action;

import com.czp.framework.action.BaseActionSupport;
import com.czp.framework.exception.IServiceException;
import com.czp.person.model.Person;
import com.czp.person.service.IPersonService;
import com.czp.user.model.User;

/**
 * 【环 境】：J2SE 1.7
 * @author   柴志鹏	CHAIZP@GMAIL.COM
 * @version  version 1.0
 * @since    2014-6-24
 */
public class PersonAction extends BaseActionSupport {
	private static final long serialVersionUID = 3099071185505617694L;
	private IPersonService personService;
	private Person person;
	
	/** 
	 * 【描 述】：查询人员信息
	 */
	public void getPersonList() {
		try {
			Person person = new Person();
			person.setStart(Integer.parseInt(request.getParameter("start")));
			person.setLimit(Integer.parseInt(request.getParameter("limit")));
			person.setPersonName(request.getParameter("personName"));
			this.responseOutPrint(
					personService.getPersonList(person));
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "getPersonList", e);
		}
	}
	
	/** 
	 * 【描 述】：添加、修改、删除人员信息
	 */
	public void personController() {
		try {
			String userId = request.getParameter("userId");
			User user = new User();//User只在删除时应用
			if(userId != null && !userId.equals("")) {
				user.setCudType(person.getCudType());
				user.setId(Integer.parseInt(userId));
			}
			
			int count = personService.personController(person, user);
			this.responseOutPrint("{success:"+ count +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "personController", e);
		}
	}
	
	/** 
	 * 【描 述】：根据人员Id查询信息
	 */
	public void findPersonById() {
		try {
			String personId = request.getParameter("personId");
			this.responseOutPrint(personService.findPersonById(personId));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "findPersonbyId", e);
		}
	}
	
	
	/** 
	 * 【描 述】：自动检索人员名称(测试方法)
	 */
	public void getPersonName() {
		try {
			String name = request.getParameter("personName");
			this.responseOutPrint(personService.getPersonName(name));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "getPersonName", e);
		}
	}
	
	/**
	 * 获取 personService
	 * @return 返回 personService
	 */
	public IPersonService getPersonService() {
		return personService;
	}
	/**
	 * 设置 personService
	 * @param 对personService进行赋值
	 */
	public void setPersonService(IPersonService personService) {
		this.personService = personService;
	}
	/**
	 * 获取 person
	 * @return 返回 person
	 */
	public Person getPerson() {
		return person;
	}
	/**
	 * 设置 person
	 * @param 对person进行赋值
	 */
	public void setPerson(Person person) {
		this.person = person;
	}
}
